{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# “网罗灯下黑”工具安利型相关数据挖掘项目\n",
    "**本项目主要是出于个人爱好与学习工具的需求为出发点，挖掘出工具类相关的安利文章，使使用者可以通过所爬取到的高频搜索标签数据快速找到对自己有所帮助的那款学习工具文章所在的位置。**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据最小可用产品\n",
    "**通过挖掘工具安利类型公众号“网罗灯下黑”截至5.14号99页的文章分类数据（标题，时间，链接）以及对文章进行标签分类，帮助用户快速检索自己需要的工具。**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 挖掘标签分类包括\n",
    "  - \"app\",\"网页\",**\"神器\"**,**\"工具\"**,\"软件\",\n",
    "  - **\"前端\"**,**\"网站\"**,\n",
    "  - \"Excel\",\"技巧\",\n",
    "  - \"网盘\",\"Windows\",**\"利器\"**,**\"电脑\"**\n",
    "  -\"安卓\",\"手机\",\"华为\"\n",
    "  - **\"下载\"**,\"系统\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 存储路径\n",
    "fn = { \"output\" : { \"公众号_htm_snippets\": \"data_raw_src/公众号_htm_snippets_{公众号}.tsv\",\n",
    "                    \"公众号_df\": \"data_raw_src/公众号_df_{公众号}.tsv\",\n",
    "                    \"公众号_xlsx\": \"data_sets/公众号_url_{公众号}.xlsx\" } \\\n",
    "      }"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 采集公众号（requests）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "5\n",
      "10\n",
      "15\n",
      "20\n"
     ]
    }
   ],
   "source": [
    "# 目标url\n",
    "\n",
    "import time\n",
    "import requests\n",
    "import pandas as pd\n",
    "import csv\n",
    "\n",
    "\n",
    "url = \"https://mp.weixin.qq.com/cgi-bin/appmsg\"\n",
    "\n",
    "# 使用Cookie，跳过登陆操作\n",
    "headers = {\n",
    "  \"Cookie\": \"ua_id=h6BFUJukQppR24zDAAAAAP8Ko6P9ttM1tDmxWUIr4tY=; pgv_pvi=3925172224; mm_lang=zh_CN; RK=qpB5Vympsv; ptcz=10f2f2bdc2f66341b2b380af7b58a083633cbf657cf1998320129ed647d97ae5; tvfe_boss_uuid=6f77702c99715285; pgv_pvid=2306298437; o_cookie=793552881; pac_uid=1_793552881; ied_qq=o0793552881; ptui_loginuin=793552881@qq.com; pgv_si=s3725672448; uuid=26fcac4e76ff1eaf398d06ea59093890; bizuin=3585789357; ticket=05e1f89364b3d65c1256fba43047b35ac96d83fb; ticket_id=gh_b49a177ff4f2; cert=KecccALJfObqQtZ8_9OxleX0VLHiHoKw; noticeLoginFlag=1; rand_info=CAESIOjVTa2oeI/pQi5Z8N3VI/w7aAjdW4tXAoAsdy2pbRJ8; slave_bizuin=3585789357; data_bizuin=3585789357; data_ticket=Xs/ewzNpU7adNG7YqeH+QrqSLniXwb2DWC2jlOUP6v3xQ3EjteeBGAjrWCvTUwsE; slave_sid=TDBHMjdkNDROQVpqMktLRUFRdkNTTnR1VmMwNFY4c0JuRTl0eVBwYURpV3pJa21EWGE4MWhEcExDX3NhM1ByakNrNGt1Rzc1S3ZWSE5TMGxHZ2dhRW14T1ZNSVhmbUEyRHVldTZrMHJjQk1tWFB3SnNqa2U4QjdMVzFkWHFKcmwyWEdvV1hORTBFcEhldWtS; slave_user=gh_b49a177ff4f2; xid=551746463a6307dae80420644f549d33; openid2ticket_orc261WvK4qVfKYsm8NiZsnV3yD4=F3R2U3xD6jna4CrlSHAotD/5TpqNUqLupVtBX3rrh7g=\",\n",
    "  \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36\" \n",
    "}\n",
    "data = {\n",
    "    \"token\": \"1184289906\",\n",
    "    \"lang\": \"zh_CN\",\n",
    "    \"f\": \"json\",\n",
    "    \"ajax\": \"1\",\n",
    "    \"action\": \"list_ex\",\n",
    "    \"begin\": \"0\",\n",
    "    \"count\": \"5\",\n",
    "    \"query\": \"\",\n",
    "    \"fakeid\": \"MzU2NTAzNzYzMg==\",\n",
    "    \"type\": \"9\",\n",
    "}\n",
    "\n",
    "\n",
    "\n",
    "content_list=[]\n",
    "\n",
    "for i in range(5):\n",
    "    data[\"begin\"] = i*5\n",
    "    print(data[\"begin\"])\n",
    "    time.sleep(3)\n",
    "    # 使用get方法进行提交\n",
    "    content_json = requests.get(url, headers=headers, params=data).json()\n",
    "#     print(content_json)\n",
    "    # 返回了一个json，里面是每一页的数据\n",
    "    for item in content_json[\"app_msg_list\"]:\n",
    "    # 提取每页文章的标题及对应的url\n",
    "        items = []\n",
    "        items.append(item[\"title\"])\n",
    "        items.append(item[\"link\"])\n",
    "        items.append(item[\"create_time\"])\n",
    "        content_list.append(items)\n",
    "\n",
    "\n",
    "name=['title','link','create_time']\n",
    "test=pd.DataFrame(columns=name,data=content_list)\n",
    "with pd.ExcelWriter(fn[\"output\"][\"公众号_xlsx\"].format(公众号=\"网罗灯下黑_requests\")) as writer:\n",
    "    test.to_excel(writer)\n",
    "\n",
    "# test.to_csv(\"../微信公众号爬虫_zhichao/南方周末.csv\",mode='a',encoding='utf-8')\n",
    "# print(\"保存成功\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 采集公众号（selenium）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from lxml.html import fromstring\n",
    "import time\n",
    "from random import random\n",
    "\n",
    "# when selenium main_content is used\n",
    "# Parses an HTML document from a string constant.  Returns the root nood\n",
    "# root = fromstring(df.loc[1,\"html_snippets\"]) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用Selenium\n",
    "* 要更改 opts.binary_location 至自己本地的Chrome浏览器，建议portable\n",
    "* Chrome浏览器 和 chromedriver.exe要同版本号到小数后一位\n",
    "* 要确保可以 开启浏览器机器人\n",
    "* 要确保浏览器机器人 可以打开网页 driver.get(\"https://mp.weixin.qq.com\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\ASUS\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:18: DeprecationWarning: use options instead of chrome_options\n"
     ]
    }
   ],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.common.desired_capabilities import DesiredCapabilities\n",
    "\n",
    "#caps=dict()\n",
    "#caps[\"pageLoadStrategy\"] = \"none\"   # Do not wait for full page load\n",
    "\n",
    "opts = webdriver.ChromeOptions()\n",
    "opts.add_argument('--no-sandbox')#解决DevToolsActivePort文件不存在的报错\n",
    "opts.add_argument('window-size=1920x3000') #指定浏览器分辨率\n",
    "opts.add_argument('--disable-gpu') #谷歌文档提到需要加上一这个属性来规避bug\n",
    "opts.add_argument('--hide-scrollbars') #隐藏滚动条, 应对些特殊页面\n",
    "#opts.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度\n",
    "#opts.add_argument('--headless') #浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败\n",
    "\n",
    "opts.binary_location = r\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" #\"H:\\_coding_\\Gitee\\InternetNewMedia\\CapstonePrj2016\\chromedriver.exe\"  \n",
    "\n",
    "# \"H:\\_coding_\\Gitee\\InternetNewMedia\\CapstonePrj2016\\chromedriver.exe\"  \n",
    "driver = webdriver.Chrome( chrome_options = opts) #desired_capabilities=caps,"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.get(\"https://mp.weixin.qq.com\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 填表登入"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "selenium 的定位方法\n",
    "* find_element_by_id &ensp;&ensp;&ensp;  根据标签id定位\n",
    "* find_element_by_name   &ensp;&ensp;&ensp; 根据标签的name定位\n",
    "* find_element_by_xpath  &ensp;&ensp;&ensp; 根据xpath定位\n",
    "* find_element_by_link_text  &ensp;&ensp;&ensp; 通过文字链接来定位元素\n",
    "* find_element_by_partial_link_text  &ensp;&ensp;&ensp;  通过文字链接来定位元素\n",
    "* find_element_by_tag_name  &ensp;&ensp;&ensp;  根据标签的名字定位\n",
    "* find_element_by_class_name  &ensp;&ensp;&ensp; 通过class name 定位\n",
    "* find_element_by_css_selector  &ensp;&ensp;&ensp;  根据元素属性来定位"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "payload =  {\"account\": \"账号\", \"password\": \"密码\"}\n",
    "driver.find_element_by_xpath('//div[@class=\"login__type__container login__type__container__scan\"]/a').click()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "WebDriver 常用方法：\n",
    "* clear()清楚文本\n",
    "* send_keys(values)模拟按键输入\n",
    "* click()模拟点击\n",
    "* submit模拟提交"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"account\"]').clear()\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"account\"]').send_keys(payload['account'])\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"password\"]').clear()\n",
    "driver.find_element_by_xpath('//form[@class=\"login_form\"]//input[@name=\"password\"]').send_keys(payload['password'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//div[@class=\"login_btn_panel\"]/a').click()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 点选单"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "其他常用方法\n",
    "* size：返回元素的尺寸\n",
    "* text：获取元素的文本\n",
    "* get_attribute：获取属性值  &ensp;&ensp;&ensp; get_attribute('innerHTML')获取元素内的全部HTML\n",
    "* is_displayed()：设置该元素用户是否可见"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'展开'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//a[@id=\"m_open\"]')\n",
    "element.click()\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "main_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.execute_script(\"window.scrollTo(0,document.body.scrollHeight)\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://mp.weixin.qq.com/cgi-bin/appmsg?begin=0&count=10&t=media/appmsg_list&type=10&action=list&token=1235951790&lang=zh_CN'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//li[@title[contains(.,\"素材管理\")]]/a') \n",
    "# main_content = element.get_attribute('innerHTML')\n",
    "# main_content\n",
    "url2= element.get_attribute(\"href\")\n",
    "url2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.get(url2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 新建图文消息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "element = driver.find_element_by_xpath('//*[text()[contains(.,\"新建图文消息\")]]') \n",
    "main_content = element.get_attribute('innerHTML')\n",
    "main_content\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['CDwindow-82545806BED6AC29D5162EE1CA9FE159', 'CDwindow-0DE3231BE7B9961763C7E5C183600AD2']\n"
     ]
    }
   ],
   "source": [
    "print (driver.window_handles)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 新建图文消息开了另一分视窗，所以要切换 switch_to \n",
    "driver.switch_to.window(driver.window_handles[-1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 超链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                超链接              \n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//*[text()[contains(.,\"超链接\")]]') \n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "选择其他公众号\n"
     ]
    }
   ],
   "source": [
    "# 点 选择其他公众号\n",
    "element = driver.find_element_by_xpath('//*[text()[contains(.,\"选择其他公众号\")]]') \n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "公众号=\"网罗灯下黑\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_xpath('//form//div[@class=\"inner_link_account_area\"]//input[@class=\"weui-desktop-form__input\"]').clear()\n",
    "driver.find_element_by_xpath('//form//div[@class=\"inner_link_account_area\"]//input[@class=\"weui-desktop-form__input\"]').send_keys(公众号)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<div class=\"weui-desktop-icon weui-desktop-icon__inputSearch weui-desktop-icon__small\"><!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----> <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M11.33 10.007l4.273 4.273a.502.502 0 0 1 .005.709l-.585.584a.499.499 0 0 1-.709-.004L10.046 11.3a6.278 6.278 0 1 1 1.284-1.294zm.012-3.729a5.063 5.063 0 1 0-10.127 0 5.063 5.063 0 0 0 10.127 0z\"></path></svg> <!----> <!----> <!----> <!----></div>\n"
     ]
    }
   ],
   "source": [
    "# 点放大镜搜\n",
    "element = driver.find_element_by_xpath('//button[@class=\"weui-desktop-icon-btn weui-desktop-search__btn\"]')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<li class=\"inner_link_account_item\"><div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/ncicWtGoBHtKUwZ0CzQHd5EokZtiavicrdnVevkhrRiaibVCK0mPSSG3nicDKUPE9GvkT6dqtO6IPX4yzIuibiatOsgjbQ/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">网罗灯下黑</strong> <i class=\"inner_link_account_wechat\">微信号：wldxh8</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div></li>\n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//ul[@class=\"inner_link_account_list\"]')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "公众号SERP = main_content\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 解析\n",
    "root = fromstring(公众号SERP) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "主 = root.xpath('//li[@class=\"inner_link_account_item\"]')\n",
    "\n",
    "account_list = []\n",
    "for e in 主:\n",
    "    account_nickname = e.xpath('./div/strong[@class=\"inner_link_account_nickname\"]')[0].text\n",
    "    account_wechat = e.xpath('./div/i[@class=\"inner_link_account_wechat\"]')[0].text\n",
    "    account_img = e.xpath('./div/img/@src')[0]\n",
    "    account = {\"nickname\": account_nickname, \"wechat\": account_wechat, \"img\": account_img,}\n",
    "    account_list.append(account)\n",
    "\n",
    "df_account = pd.DataFrame(account_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>nickname</th>\n",
       "      <th>wechat</th>\n",
       "      <th>img</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>网罗灯下黑</td>\n",
       "      <td>微信号：wldxh8</td>\n",
       "      <td>http://mmbiz.qpic.cn/mmbiz_png/ncicWtGoBHtKUwZ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  nickname      wechat                                                img\n",
       "0    网罗灯下黑  微信号：wldxh8  http://mmbiz.qpic.cn/mmbiz_png/ncicWtGoBHtKUwZ..."
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<div class=\"weui-desktop-vm_primary\"><img src=\"http://mmbiz.qpic.cn/mmbiz_png/ncicWtGoBHtKUwZ0CzQHd5EokZtiavicrdnVevkhrRiaibVCK0mPSSG3nicDKUPE9GvkT6dqtO6IPX4yzIuibiatOsgjbQ/0?wx_fmt=png\" class=\"inner_link_account_avatar\"> <strong class=\"inner_link_account_nickname\">网罗灯下黑</strong> <i class=\"inner_link_account_wechat\">微信号：wldxh8</i></div> <div class=\"weui-desktop-vm_default inner_link_account_type\">订阅号</div>\n"
     ]
    }
   ],
   "source": [
    "element = driver.find_element_by_xpath('//ul[@class=\"inner_link_account_list\"]/li')\n",
    "main_content = element.get_attribute('innerHTML')\n",
    "print(main_content)\n",
    "element.click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n跳转_input = driver.find_element_by_xpath(\\'//span[@class=\"weui-desktop-pagination__form\"]/input\\')\\n跳转_a = driver.find_element_by_xpath(\\'//span[@class=\"weui-desktop-pagination__form\"]/a\\')\\n跳转_input.clear()\\n跳转_input.send_keys(2)\\n跳转_a.click()\\n'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 跳转testing\n",
    "'''\n",
    "跳转_input = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/input')\n",
    "跳转_a = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/a')\n",
    "跳转_input.clear()\n",
    "跳转_input.send_keys(2)\n",
    "跳转_a.click()\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 99]\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 跳转上限\n",
    "l_e = driver.find_elements_by_xpath('//label[@class=\"weui-desktop-pagination__num\"]')\n",
    "l_e_int  = [int(x.text) for x in l_e] \n",
    "print (l_e_int)\n",
    "print (l_e_int[0]==l_e_int[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]\n"
     ]
    }
   ],
   "source": [
    "pages = list(range(l_e_int[0],l_e_int[-1]+1 ))\n",
    "#print(pages[0:2])\n",
    "pages = list(range(1,l_e_int[-1]+1 ))\n",
    "print(pages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]\n"
     ]
    }
   ],
   "source": [
    "print(pages[:50])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]\n"
     ]
    }
   ],
   "source": [
    "print(pages[50:])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 循环/遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "global varialbes \n",
    "html_raw = dict()\n",
    "main_content =\"\"\n",
    "element = None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "def process_pages (pages):\n",
    "    for p in pages:\n",
    "        print (p,end='\\t')\n",
    "\n",
    "        跳转_input = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/input')\n",
    "        跳转_a = driver.find_element_by_xpath('//span[@class=\"weui-desktop-pagination__form\"]/a')\n",
    "        跳转_input.clear()\n",
    "        跳转_input.send_keys(p)\n",
    "        跳转_a.click()\n",
    "        time.sleep(45+40*random())\n",
    "        element = driver.find_element_by_xpath('//div[@class=\"inner_link_article_list\"]')\n",
    "        main_content = element.get_attribute('innerHTML')\n",
    "        html_raw[p] = main_content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\t25\t26\t27\t28\t29\t30\t31\t32\t33\t34\t35\t36\t37\t38\t39\t40\t41\t42\t43\t44\t45\t46\t47\t48\t49\t50\t51\t52\t53\t54\t55\t56\t57\t58\t59\t60\t61\t62\t63\t64\t65\t66\t67\t68\t69\t70\t71\t72\t73\t74\t75\t76\t77\t78\t79\t80\t81\t82\t83\t84\t85\t86\t87\t88\t89\t90\t91\t92\t93\t94\t95\t96\t97\t98\t99\t"
     ]
    }
   ],
   "source": [
    "process_pages(pages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>html_snippets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>&lt;div&gt;&lt;label class=\"inner_link_article_item\"&gt;&lt;s...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>99 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        html_snippets\n",
       "1   <div><label class=\"inner_link_article_item\"><s...\n",
       "2   <div><label class=\"inner_link_article_item\"><s...\n",
       "3   <div><label class=\"inner_link_article_item\"><s...\n",
       "4   <div><label class=\"inner_link_article_item\"><s...\n",
       "5   <div><label class=\"inner_link_article_item\"><s...\n",
       "..                                                ...\n",
       "95  <div><label class=\"inner_link_article_item\"><s...\n",
       "96  <div><label class=\"inner_link_article_item\"><s...\n",
       "97  <div><label class=\"inner_link_article_item\"><s...\n",
       "98  <div><label class=\"inner_link_article_item\"><s...\n",
       "99  <div><label class=\"inner_link_article_item\"><s...\n",
       "\n",
       "[99 rows x 1 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([html_raw]).T\n",
    "df.columns = [\"html_snippets\"]\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stored 'html_raw' (dict)\n"
     ]
    }
   ],
   "source": [
    "%store html_raw\n",
    "import pickle \n",
    "filehandler = open(\"html_raw\", 'wb') \n",
    "pickle.dump(html_raw, filehandler)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>html_snippets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [html_snippets]\n",
       "Index: []"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_out = df[~df.duplicated()]\n",
    "print (len(df_out))\n",
    "df[df.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "try_again = list(df[df.duplicated()].index)\n",
    "print(try_again)\n",
    "try_again = try_again + list (set(pages).difference(set(df.index.values)))\n",
    "try_again"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 暂存档"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "filename = fn [\"output\"] [\"公众号_htm_snippets\"] \n",
    "df_out.to_csv(filename.format(公众号=公众号), sep=\"\\t\", encoding=\"utf8\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12,12,11,11,12,12,8,10,12,12,9,11,12,13,10,13,12,9,10,12,11,11,11,11,11,12,8,8,8,7,9,8,8,9,9,8,9,8,9,10,9,9,9,9,9,6,8,9,8,9,7,5,8,7,10,7,8,8,8,8,9,9,9,8,7,8,6,9,7,8,6,5,5,5,5,6,5,5,5,5,5,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,5,3,"
     ]
    }
   ],
   "source": [
    "def parse_html_snippets(_snippet_):\n",
    "    root = fromstring(_snippet_) \n",
    "    title = [x.text for x in root.xpath('//div[@class=\"inner_link_article_title\"]')]\n",
    "    create_time = [x.text for x in root.xpath('//div[@class=\"inner_link_article_date\"]')]\n",
    "    link = [x for x in root.xpath('//a/@href')]\n",
    "    _df_ = pd.DataFrame({\"title\":title, \"create_time\": create_time, \"link\":link})\n",
    "    return(_df_)\n",
    "    \n",
    "l_df = []\n",
    "for p in pages:\n",
    "    _df_ = parse_html_snippets(df.loc[p,\"html_snippets\"])\n",
    "    print (len(_df_), end=\",\")\n",
    "    l_df.append(_df_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>这是个bug？限时领取6T空间满速下载的1年云盘会员！</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>在华为和三星面前，苹果直接跪了？</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>台式机你买品牌机还是自己组装？</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>这是1年来首次用神器来夸1个软件，建议你们都用上它</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>这家公司的名字神TM奇葩，心太大了</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>你会给店家的服务打差评吗？</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>一键屏蔽各大视频网站的片头广告，这可能是最简单的方法</td>\n",
       "      <td>2020-05-08</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Intel和AMD原来是这种关系，过于真实</td>\n",
       "      <td>2020-05-08</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>机械键盘你喜欢用哪种轴？</td>\n",
       "      <td>2020-05-08</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>我花3天对比了8个手机应用商店 发现了这个你从未留意过的细节</td>\n",
       "      <td>2020-05-06</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>被《后浪》刷屏了？来看看这个成人翻译版</td>\n",
       "      <td>2020-05-06</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             title create_time  \\\n",
       "0      这是个bug？限时领取6T空间满速下载的1年云盘会员！  2020-05-13   \n",
       "1                 在华为和三星面前，苹果直接跪了？  2020-05-13   \n",
       "2                  台式机你买品牌机还是自己组装？  2020-05-13   \n",
       "3        这是1年来首次用神器来夸1个软件，建议你们都用上它  2020-05-11   \n",
       "4                这家公司的名字神TM奇葩，心太大了  2020-05-11   \n",
       "5                    你会给店家的服务打差评吗？  2020-05-11   \n",
       "6       一键屏蔽各大视频网站的片头广告，这可能是最简单的方法  2020-05-08   \n",
       "7            Intel和AMD原来是这种关系，过于真实  2020-05-08   \n",
       "8                     机械键盘你喜欢用哪种轴？  2020-05-08   \n",
       "9   我花3天对比了8个手机应用商店 发现了这个你从未留意过的细节  2020-05-06   \n",
       "10             被《后浪》刷屏了？来看看这个成人翻译版  2020-05-06   \n",
       "\n",
       "                                                 link  \n",
       "0   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "1   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "2   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "3   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "4   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "5   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "6   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "7   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "8   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "9   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "10  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  "
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out = pd.concat(l_df).reset_index(drop=True)\n",
    "df_url_out.loc[0:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>791</th>\n",
       "      <td>iOS 11是在逗我玩吗？这样奇葩的相机扫码谁会用？</td>\n",
       "      <td>2017-09-24</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>792</th>\n",
       "      <td>仅从技术角度分析薛之谦微信聊天截图真伪，三观不稳者慎入！</td>\n",
       "      <td>2017-09-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>793</th>\n",
       "      <td>有哪些用后被感动到起鸡皮疙瘩的产品神细节？</td>\n",
       "      <td>2017-09-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>794</th>\n",
       "      <td>刚刚，苹果宣布取消“苹果税”，向腾讯认输！</td>\n",
       "      <td>2017-09-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>795</th>\n",
       "      <td>刷了两天iPhone X，居然没有人提到这个问题？</td>\n",
       "      <td>2017-09-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            title create_time  \\\n",
       "791    iOS 11是在逗我玩吗？这样奇葩的相机扫码谁会用？  2017-09-24   \n",
       "792  仅从技术角度分析薛之谦微信聊天截图真伪，三观不稳者慎入！  2017-09-21   \n",
       "793         有哪些用后被感动到起鸡皮疙瘩的产品神细节？  2017-09-19   \n",
       "794         刚刚，苹果宣布取消“苹果税”，向腾讯认输！  2017-09-17   \n",
       "795     刷了两天iPhone X，居然没有人提到这个问题？  2017-09-15   \n",
       "\n",
       "                                                  link  \n",
       "791  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "792  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "793  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "794  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "795  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  "
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out.tail(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>value</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>这是个bug？限时领取6T空间满速下载的1年云盘会员！</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>在华为和三星面前，苹果直接跪了？</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>台式机你买品牌机还是自己组装？</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>这家公司的名字神TM奇葩，心太大了</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>你会给店家的服务打差评吗？</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>791</th>\n",
       "      <td>iOS 11是在逗我玩吗？这样奇葩的相机扫码谁会用？</td>\n",
       "      <td>2017-09-24</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>792</th>\n",
       "      <td>仅从技术角度分析薛之谦微信聊天截图真伪，三观不稳者慎入！</td>\n",
       "      <td>2017-09-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>793</th>\n",
       "      <td>有哪些用后被感动到起鸡皮疙瘩的产品神细节？</td>\n",
       "      <td>2017-09-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>794</th>\n",
       "      <td>刚刚，苹果宣布取消“苹果税”，向腾讯认输！</td>\n",
       "      <td>2017-09-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>795</th>\n",
       "      <td>刷了两天iPhone X，居然没有人提到这个问题？</td>\n",
       "      <td>2017-09-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>562 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                              title create_time  \\\n",
       "value                                             \n",
       "0       这是个bug？限时领取6T空间满速下载的1年云盘会员！  2020-05-13   \n",
       "1                  在华为和三星面前，苹果直接跪了？  2020-05-13   \n",
       "2                   台式机你买品牌机还是自己组装？  2020-05-13   \n",
       "4                 这家公司的名字神TM奇葩，心太大了  2020-05-11   \n",
       "5                     你会给店家的服务打差评吗？  2020-05-11   \n",
       "...                             ...         ...   \n",
       "791      iOS 11是在逗我玩吗？这样奇葩的相机扫码谁会用？  2017-09-24   \n",
       "792    仅从技术角度分析薛之谦微信聊天截图真伪，三观不稳者慎入！  2017-09-21   \n",
       "793           有哪些用后被感动到起鸡皮疙瘩的产品神细节？  2017-09-19   \n",
       "794           刚刚，苹果宣布取消“苹果税”，向腾讯认输！  2017-09-17   \n",
       "795       刷了两天iPhone X，居然没有人提到这个问题？  2017-09-15   \n",
       "\n",
       "                                                    link  \n",
       "value                                                     \n",
       "0      http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "1      http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "2      http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "4      http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "5      http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "...                                                  ...  \n",
       "791    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "792    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "793    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "794    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "795    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "\n",
       "[562 rows x 3 columns]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# tagging 标记\n",
    "tagging_list = [\"\",\"app\",\"网页\",\"神器\",\"工具\",\"软件\",\n",
    "                \"前端\",\"网站\",\n",
    "                \"Excel\",\"技巧\",\n",
    "                \"网盘\",\"Windows\",\"利器\",\"电脑\"\n",
    "                \"安卓\",\"手机\",\"华为\"\n",
    "                \"下载\",\"系统\"] #overwritable\n",
    "\n",
    "v_v_list = []\n",
    "\n",
    "for tag in tagging_list:\n",
    "    index_list = df_url_out [ df_url_out.title.str.contains(tag) ].index.tolist()\n",
    "    v_v_pairs = pd.DataFrame({tag:index_list}).melt().set_index(\"value\")\n",
    "    v_v_list.append(v_v_pairs)\n",
    "\n",
    "df_cat = v_v_list[0]\n",
    "for d in v_v_list:\n",
    "    df_cat.update(d)\n",
    "    \n",
    "# 尚未标记内容\n",
    "df_url_out.loc [ df_cat.query('variable==\"\"').index ]"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "df_url_out.loc[30].link"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [title, create_time, link]\n",
       "Index: []"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out[df_url_out.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>这是个bug？限时领取6T空间满速下载的1年云盘会员！</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>在华为和三星面前，苹果直接跪了？</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>台式机你买品牌机还是自己组装？</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>这是1年来首次用神器来夸1个软件，建议你们都用上它</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>这家公司的名字神TM奇葩，心太大了</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>791</th>\n",
       "      <td>iOS 11是在逗我玩吗？这样奇葩的相机扫码谁会用？</td>\n",
       "      <td>2017-09-24</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>792</th>\n",
       "      <td>仅从技术角度分析薛之谦微信聊天截图真伪，三观不稳者慎入！</td>\n",
       "      <td>2017-09-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>793</th>\n",
       "      <td>有哪些用后被感动到起鸡皮疙瘩的产品神细节？</td>\n",
       "      <td>2017-09-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>794</th>\n",
       "      <td>刚刚，苹果宣布取消“苹果税”，向腾讯认输！</td>\n",
       "      <td>2017-09-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>795</th>\n",
       "      <td>刷了两天iPhone X，居然没有人提到这个问题？</td>\n",
       "      <td>2017-09-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>796 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                            title create_time  \\\n",
       "0     这是个bug？限时领取6T空间满速下载的1年云盘会员！  2020-05-13   \n",
       "1                在华为和三星面前，苹果直接跪了？  2020-05-13   \n",
       "2                 台式机你买品牌机还是自己组装？  2020-05-13   \n",
       "3       这是1年来首次用神器来夸1个软件，建议你们都用上它  2020-05-11   \n",
       "4               这家公司的名字神TM奇葩，心太大了  2020-05-11   \n",
       "..                            ...         ...   \n",
       "791    iOS 11是在逗我玩吗？这样奇葩的相机扫码谁会用？  2017-09-24   \n",
       "792  仅从技术角度分析薛之谦微信聊天截图真伪，三观不稳者慎入！  2017-09-21   \n",
       "793         有哪些用后被感动到起鸡皮疙瘩的产品神细节？  2017-09-19   \n",
       "794         刚刚，苹果宣布取消“苹果税”，向腾讯认输！  2017-09-17   \n",
       "795     刷了两天iPhone X，居然没有人提到这个问题？  2017-09-15   \n",
       "\n",
       "                                                  link  \n",
       "0    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "1    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "2    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "3    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "4    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "..                                                 ...  \n",
       "791  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "792  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "793  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "794  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "795  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...  \n",
       "\n",
       "[796 rows x 3 columns]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_url_out[~df_url_out.duplicated()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "      <th>variable</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>这是个bug？限时领取6T空间满速下载的1年云盘会员！</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>在华为和三星面前，苹果直接跪了？</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>台式机你买品牌机还是自己组装？</td>\n",
       "      <td>2020-05-13</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>这是1年来首次用神器来夸1个软件，建议你们都用上它</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>这家公司的名字神TM奇葩，心太大了</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>791</th>\n",
       "      <td>iOS 11是在逗我玩吗？这样奇葩的相机扫码谁会用？</td>\n",
       "      <td>2017-09-24</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>792</th>\n",
       "      <td>仅从技术角度分析薛之谦微信聊天截图真伪，三观不稳者慎入！</td>\n",
       "      <td>2017-09-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>793</th>\n",
       "      <td>有哪些用后被感动到起鸡皮疙瘩的产品神细节？</td>\n",
       "      <td>2017-09-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>794</th>\n",
       "      <td>刚刚，苹果宣布取消“苹果税”，向腾讯认输！</td>\n",
       "      <td>2017-09-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>795</th>\n",
       "      <td>刷了两天iPhone X，居然没有人提到这个问题？</td>\n",
       "      <td>2017-09-15</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>无法分类</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>796 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                            title create_time  \\\n",
       "0     这是个bug？限时领取6T空间满速下载的1年云盘会员！  2020-05-13   \n",
       "1                在华为和三星面前，苹果直接跪了？  2020-05-13   \n",
       "2                 台式机你买品牌机还是自己组装？  2020-05-13   \n",
       "3       这是1年来首次用神器来夸1个软件，建议你们都用上它  2020-05-11   \n",
       "4               这家公司的名字神TM奇葩，心太大了  2020-05-11   \n",
       "..                            ...         ...   \n",
       "791    iOS 11是在逗我玩吗？这样奇葩的相机扫码谁会用？  2017-09-24   \n",
       "792  仅从技术角度分析薛之谦微信聊天截图真伪，三观不稳者慎入！  2017-09-21   \n",
       "793         有哪些用后被感动到起鸡皮疙瘩的产品神细节？  2017-09-19   \n",
       "794         刚刚，苹果宣布取消“苹果税”，向腾讯认输！  2017-09-17   \n",
       "795     刷了两天iPhone X，居然没有人提到这个问题？  2017-09-15   \n",
       "\n",
       "                                                  link variable  \n",
       "0    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...     无法分类  \n",
       "1    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...     无法分类  \n",
       "2    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...     无法分类  \n",
       "3    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "4    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...     无法分类  \n",
       "..                                                 ...      ...  \n",
       "791  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...     无法分类  \n",
       "792  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...     无法分类  \n",
       "793  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...     无法分类  \n",
       "794  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...     无法分类  \n",
       "795  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...     无法分类  \n",
       "\n",
       "[796 rows x 4 columns]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_o = df_url_out.join(df_cat).replace(\"\", np.nan).fillna(\"无法分类\")\n",
    "df_o"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>create_time</th>\n",
       "      <th>link</th>\n",
       "      <th>variable</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>这是1年来首次用神器来夸1个软件，建议你们都用上它</td>\n",
       "      <td>2020-05-11</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>扶好下巴，吾爱破解上这个软件可能打开了潘多拉的魔盒</td>\n",
       "      <td>2020-04-17</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>141</th>\n",
       "      <td>谁是 2019 年度最佳软件？</td>\n",
       "      <td>2020-02-02</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>新年重磅：开号以来的全部精品软件合集！</td>\n",
       "      <td>2020-01-31</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>166</th>\n",
       "      <td>调查：你喜欢更新软件吗?</td>\n",
       "      <td>2020-01-06</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182</th>\n",
       "      <td>抢票软件哪家强？3天内抢了20多次，被封了3次号，实测告诉你答案</td>\n",
       "      <td>2019-12-25</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>284</th>\n",
       "      <td>​为啥一直不写这种软件？因为微信会封号</td>\n",
       "      <td>2019-10-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>294</th>\n",
       "      <td>两年来写过的软件全集大阅兵！90%的问题这里都有答案</td>\n",
       "      <td>2019-10-07</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>302</th>\n",
       "      <td>为什么这些软件都想“约”？</td>\n",
       "      <td>2019-09-23</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>379</th>\n",
       "      <td>免费下载正版付费软件？这个网站你需要知道</td>\n",
       "      <td>2019-07-08</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>网站</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>393</th>\n",
       "      <td>黑哥的违规血泪史：这些软件不要用了，会被微信封号！</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>422</th>\n",
       "      <td>“你们这些玩软件的只会耍小聪明！”</td>\n",
       "      <td>2019-05-24</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444</th>\n",
       "      <td>五一放假不休息，开号以来的全部精品软件汇总更新！</td>\n",
       "      <td>2019-05-05</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>515</th>\n",
       "      <td>新年第一更：开号以来的全部精品软件汇总更新！</td>\n",
       "      <td>2019-02-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>574</th>\n",
       "      <td>酷安排名第一、下载量超百万！这款清理软件凭什么？（限量送永久会员码）</td>\n",
       "      <td>2018-12-03</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>604</th>\n",
       "      <td>用了这么多记账软件，要说适合懒人用还得属它！（领现金红包）</td>\n",
       "      <td>2018-10-31</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>620</th>\n",
       "      <td>开号以来的全部精品软件全在这里了！</td>\n",
       "      <td>2018-10-08</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>627</th>\n",
       "      <td>你是戏精？这款社交软件适合你没错了！</td>\n",
       "      <td>2018-09-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>632</th>\n",
       "      <td>限时福利！8款正版软件免费领取，价值350美刀！系统优化、广告屏蔽、PDF编辑……</td>\n",
       "      <td>2018-09-14</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>系统</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>634</th>\n",
       "      <td>可能是最好用的电视直播软件，5000+国内外高清电视频道都能看！</td>\n",
       "      <td>2018-09-12</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>635</th>\n",
       "      <td>我下的软件到底安全吗？</td>\n",
       "      <td>2018-09-10</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>656</th>\n",
       "      <td>警告！千万别让你女朋友在你电脑上打开这个软件！</td>\n",
       "      <td>2018-08-02</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>691</th>\n",
       "      <td>送你一个云端电脑，让你的电脑少装几十款软件（内有彩蛋）</td>\n",
       "      <td>2018-05-18</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>700</th>\n",
       "      <td>没想到这个 800k 的录屏软件功能居然这么神奇！</td>\n",
       "      <td>2018-04-26</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>702</th>\n",
       "      <td>可能是东半球最好用的压缩工具软件，有一招连 WinRAR 都被按在地上反复摩擦！</td>\n",
       "      <td>2018-04-23</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>707</th>\n",
       "      <td>仅限最后两天！领取488元的世界顶级备份软件激活码！</td>\n",
       "      <td>2018-04-12</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>733</th>\n",
       "      <td>记什么账？什么记账？这款软件全自动同步账单，从此再无手动记账！</td>\n",
       "      <td>2018-01-30</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>744</th>\n",
       "      <td>有了这个2m的小软件，你可以把手机上90%的app打入冷宫</td>\n",
       "      <td>2018-01-05</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>手机</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>748</th>\n",
       "      <td>到底哪款OCR软件识别率最高？免费版居然表现最佳？</td>\n",
       "      <td>2017-12-27</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>768</th>\n",
       "      <td>唉，我怎么今天才知道这款软件，感觉白玩了这么多年电脑！</td>\n",
       "      <td>2017-11-12</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>772</th>\n",
       "      <td>革掉那些“装机必备”软件的命——资源管理器篇</td>\n",
       "      <td>2017-11-06</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>775</th>\n",
       "      <td>小白都会用的视频广告屏蔽软件，还能高速下载百度云文件</td>\n",
       "      <td>2017-11-02</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779</th>\n",
       "      <td>这个软件上每天都有人因为约炮被骗400万</td>\n",
       "      <td>2017-10-27</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>785</th>\n",
       "      <td>全网视频广告屏蔽效果最好的软件下架了，还好这里能下载</td>\n",
       "      <td>2017-10-19</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>软件</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>790</th>\n",
       "      <td>如果手机上只能保留一个软件，我会选择这个</td>\n",
       "      <td>2017-09-27</td>\n",
       "      <td>http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...</td>\n",
       "      <td>手机</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         title create_time  \\\n",
       "3                    这是1年来首次用神器来夸1个软件，建议你们都用上它  2020-05-11   \n",
       "35                   扶好下巴，吾爱破解上这个软件可能打开了潘多拉的魔盒  2020-04-17   \n",
       "141                            谁是 2019 年度最佳软件？  2020-02-02   \n",
       "145                        新年重磅：开号以来的全部精品软件合集！  2020-01-31   \n",
       "166                               调查：你喜欢更新软件吗?  2020-01-06   \n",
       "182           抢票软件哪家强？3天内抢了20多次，被封了3次号，实测告诉你答案  2019-12-25   \n",
       "284                        ​为啥一直不写这种软件？因为微信会封号  2019-10-14   \n",
       "294                 两年来写过的软件全集大阅兵！90%的问题这里都有答案  2019-10-07   \n",
       "302                              为什么这些软件都想“约”？  2019-09-23   \n",
       "379                       免费下载正版付费软件？这个网站你需要知道  2019-07-08   \n",
       "393                  黑哥的违规血泪史：这些软件不要用了，会被微信封号！  2019-06-21   \n",
       "422                          “你们这些玩软件的只会耍小聪明！”  2019-05-24   \n",
       "444                   五一放假不休息，开号以来的全部精品软件汇总更新！  2019-05-05   \n",
       "515                     新年第一更：开号以来的全部精品软件汇总更新！  2019-02-10   \n",
       "574         酷安排名第一、下载量超百万！这款清理软件凭什么？（限量送永久会员码）  2018-12-03   \n",
       "604              用了这么多记账软件，要说适合懒人用还得属它！（领现金红包）  2018-10-31   \n",
       "620                          开号以来的全部精品软件全在这里了！  2018-10-08   \n",
       "627                         你是戏精？这款社交软件适合你没错了！  2018-09-19   \n",
       "632  限时福利！8款正版软件免费领取，价值350美刀！系统优化、广告屏蔽、PDF编辑……  2018-09-14   \n",
       "634           可能是最好用的电视直播软件，5000+国内外高清电视频道都能看！  2018-09-12   \n",
       "635                                我下的软件到底安全吗？  2018-09-10   \n",
       "656                    警告！千万别让你女朋友在你电脑上打开这个软件！  2018-08-02   \n",
       "691                送你一个云端电脑，让你的电脑少装几十款软件（内有彩蛋）  2018-05-18   \n",
       "700                  没想到这个 800k 的录屏软件功能居然这么神奇！  2018-04-26   \n",
       "702   可能是东半球最好用的压缩工具软件，有一招连 WinRAR 都被按在地上反复摩擦！  2018-04-23   \n",
       "707                 仅限最后两天！领取488元的世界顶级备份软件激活码！  2018-04-12   \n",
       "733            记什么账？什么记账？这款软件全自动同步账单，从此再无手动记账！  2018-01-30   \n",
       "744              有了这个2m的小软件，你可以把手机上90%的app打入冷宫  2018-01-05   \n",
       "748                  到底哪款OCR软件识别率最高？免费版居然表现最佳？  2017-12-27   \n",
       "768                唉，我怎么今天才知道这款软件，感觉白玩了这么多年电脑！  2017-11-12   \n",
       "772                     革掉那些“装机必备”软件的命——资源管理器篇  2017-11-06   \n",
       "775                 小白都会用的视频广告屏蔽软件，还能高速下载百度云文件  2017-11-02   \n",
       "779                       这个软件上每天都有人因为约炮被骗400万  2017-10-27   \n",
       "785                 全网视频广告屏蔽效果最好的软件下架了，还好这里能下载  2017-10-19   \n",
       "790                       如果手机上只能保留一个软件，我会选择这个  2017-09-27   \n",
       "\n",
       "                                                  link variable  \n",
       "3    http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "35   http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "141  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "145  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "166  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "182  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "284  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "294  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "302  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "379  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       网站  \n",
       "393  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "422  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "444  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "515  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "574  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "604  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "620  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "627  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "632  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       系统  \n",
       "634  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "635  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "656  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "691  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "700  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "702  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "707  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "733  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "744  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       手机  \n",
       "748  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "768  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "772  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "775  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "779  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "785  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       软件  \n",
       "790  http://mp.weixin.qq.com/s?__biz=MzU2NTAzNzYzMg...       手机  "
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_o[df_o.title.str.contains(\"软件\")]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>variable</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>无法分类</th>\n",
       "      <td>562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>手机</th>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>软件</th>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>网站</th>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>神器</th>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>利器</th>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>工具</th>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>网盘</th>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>技巧</th>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Windows</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>系统</th>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>网页</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Excel</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>app</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          title\n",
       "variable       \n",
       "无法分类        562\n",
       "手机           59\n",
       "软件           31\n",
       "网站           26\n",
       "神器           23\n",
       "利器           22\n",
       "工具           22\n",
       "网盘           22\n",
       "技巧            7\n",
       "Windows       6\n",
       "系统            6\n",
       "网页            5\n",
       "Excel         3\n",
       "app           2"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_stats = df_o.groupby(by=\"variable\").agg({\"title\":\"count\"}).sort_values(by=\"title\", ascending=False)\n",
    "df_stats"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_account.columns.name = \"rel_accounts\"\n",
    "df_o.columns.name = \"url_cat\"\n",
    "df_stats.columns.name = \"stats\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "_df_.columns.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get the xlsxwriter workbook and worksheet objects.  \n",
    "with pd.ExcelWriter(fn[\"output\"][\"公众号_xlsx\"].format(公众号=公众号)) as writer:\n",
    "    workbook  = writer.book\n",
    "\n",
    "    for _df_ in [df_account, df_o, df_stats]:\n",
    "        _df_.to_excel(writer, sheet_name = _df_.columns.name)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 总结\n",
    "- 采集公众号request是通过模拟浏览器（获取cookie与user-agent信息），结合xpath与简单的for循环进行翻页操作的\n",
    "- 采集公众号selenium的方法更高级一些，它是一种模拟人类点击的自动化爬虫（selenium模块与driver插件相结合），更具灵活性（页码不需要解析，可以直接点击进行翻页，我们只需要简单计算一下最大值和最小值）\n",
    "- 两者都需要“注意礼貌”，不要爬的的太快，要注意使用time.sleep与random\n",
    "    - 同时每爬取四五十页数休息一小时也是个不错的想法\n",
    "- 无论是使用request还是selenium都有可能遇到“操作频繁”的警告，这个时候很可能是被发现了，不过我们可以通过清除浏览器的cookie的方法解决，同时注意一小时后再登陆，重新登陆后你会发现cookie和token已经发生了变化，因而要进行响应的更改。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
